#include "candotemptab.h"
#include "ui_candotemptab.h"
#include "mainwindow.h"

CanDoTemptab::CanDoTemptab(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CanDoTemptab)
{
    ui->setupUi(this);
}

CanDoTemptab::~CanDoTemptab()
{
    delete ui;
}

void CanDoTemptab::ProcessMessage(const CanMessage &mess)
{
    ui->StateValue->setText(MainWindow::ConvertChargeStateEnumToText((MainWindow::ChargerStates)mess.GetData()[0]));
    ui->Sensor1Value->setText(ConvertSensorCANToText(mess.GetData()[1]));
    ui->Sensor2Value->setText(ConvertSensorCANToText(mess.GetData()[2]));
    ui->Sensor3Value->setText(ConvertSensorCANToText(mess.GetData()[3]));
    ui->Sensor4Value->setText(ConvertSensorCANToText(mess.GetData()[4]));
    ui->Sensor5Value->setText(ConvertSensorCANToText(mess.GetData()[5]));
    ui->Sensor6Value->setText(ConvertSensorCANToText(mess.GetData()[6]));
    ui->Sensor7Value->setText(ConvertSensorCANToText(mess.GetData()[7]));
}

QString CanDoTemptab::ConvertSensorCANToText(int CANData)
{
    QString retVal = "Not Installed";
    if(CANData == 0xfe)
    {
        retVal = "Missing";
    }
    else
    {
        retVal = QString::number(CANData - 100);
    }
    return retVal;

}
